package com.qiyu.dubbo.config.starter.cluster;

import org.apache.dubbo.common.URL;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.RpcException;
import org.apache.dubbo.rpc.cluster.Router;

import java.util.List;

/**
 * 自定义的一个router组件
 * @author linhao
 * @date created in 5:11 下午 2020/11/21
 */
public class LimitIpRouter implements Router {
    @Override
    public URL getUrl() {
        return null;
    }

    @Override
    public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException {
        //每次请求都会被切入到这个route模块
        System.out.println(this.getName());
        for (Invoker<T> invoker : invokers) {
            System.out.println(invoker.getUrl().toString());
        }
        return invokers;
    }

    @Override
    public boolean isRuntime() {
        return false;
    }

    @Override
    public boolean isForce() {
        return false;
    }

    @Override
    public int getPriority() {
        return -100;
    }

    public String getName(){
        return " ====== this is limit ip router ====== ";
    }
}
